package com.xwtec.juc.c_009;

import java.util.concurrent.TimeUnit;

/**
 * @Author: zt
 * @Date: 2021/3/19 17:06
 *
 * 线程产生异常时，默认会释放锁
 */
public class T {


    private int count =0;
    synchronized void m(){

        System.out.println(Thread.currentThread().getName()+"m start");
        while(true){
            System.out.println(Thread.currentThread().getName()+",count"+count);
            count++;
            try {
                TimeUnit.MILLISECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(count==5){
                int i =count/0;
                System.out.println(i);
            }

        }
    }

    public static void main(String[] args) {
        T t = new T();
        new Thread(()->t.m()).start();
        new Thread(()->t.m()).start();
    }
}
